package edu.cdnu.common.result;

import edu.cdnu.utils.ResourcesUtil;

/**
 * (分页)
 * @author ASUS AsingZ
 * @param <T>
 */
public class PageResultEntity<T> {
	/**
	 * 状态码
	 */
	private int code;
	/**
	 * 消息
	 */
	private String message;
	/**
	 * 总条数
	 */
	private int count;
	/**
	 * 数据 
	 */
	private T data;
	
	public PageResultEntity(int code, String message, int count, T data) {
		super();
		this.code = code;
		this.message = message;
		this.count = count;
		this.data = data;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	/**
	 * 创建成功 code 200
	 * @param count 总条数
	 * @param data 数据列表
	 * @return
	 */
	public  static<T>  PageResultEntity<T> createSuccessResult(int count,T data){
		PageResultEntity<T> pageResult = new PageResultEntity<T>(200,"成功",count,data);
		return pageResult;
	}
	
	/**
	 * 创建错误的返回
	 * @param code 错误代码 MessageConstatnt接口中定义
	 * @return
	 */
	public  static<T> PageResultEntity<T> createFailResult(Integer code){
		PageResultEntity<T> pageResult = new PageResultEntity<T>(Integer.valueOf(code),ResourcesUtil.getMessageByCode(code),0,null);
		return pageResult;
	}
	
	
}
